package br.edu.univas.locadoragraph.dao;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;

import br.edu.univas.locadoragraph.database.Keys;

public class GenderDAO {

	public Node saveGenderGraph(String gender, Index<Node> index, GraphDatabaseService graph) {
		System.out.println("Method: Save Gender");
		long start = System.currentTimeMillis();
		
		Node node = null;
		Transaction tx = graph.beginTx();
			try {
				node = graph.createNode();
				node.setProperty(Keys.GENDERKEY, gender.toLowerCase());
				index.add(node, Keys.GENDERKEY, gender.toLowerCase());

				System.out.println("Node Gender: " + node);
				tx.success();
				tx.finish();
			} catch (Exception e) {
				tx.failure();
				tx.finish();
			}
			
		double total = (System.currentTimeMillis() - start);
		System.out.println("Gender not saved! Time: " + total / 1000);
		return node;
	}
}
